<?php
namespace app\admin\model;

use think\Model;

class Project extends Model
{
    
    /**
     * 获取项目
     * @param $where 条件
     * @param $field 查询字段
     * @author cpy(1442435897@qq.com)
     * @return  array
     */
    public function selectInfo($where, $field = '*') {
        $res = $this->where($where)->field($field)->order('create_time desc')->select();
        return empty($res) ? array() : $res->toArray();
    }
    
    protected $insert  = ['start_time','end_time','release_time','create_time','tags'];
	public function Team(){
		return $this->hasOne('team','id','initiator')->field('team_name');
	}
	
    protected function setStartTimeAttr()
    {
        return strtotime(input('post.start_time'));
    }
    
    protected function setEndTimeAttr()
    {
        return strtotime(input('post.end_time'));
    }
	
    protected function setReleaseTimeAttr()
    {
        return strtotime(input('post.release_time'));
    }
	
    protected function setCreateTimeAttr()
    {
        return strtotime(input('post.create_time')?input('post.create_time'):date('Y-m-s H:i:s'));
    }
	
	protected function setTagsAttr(){
		return serialize(input('post.tags/a'));
	}
	
	protected function getStartTimeAttr($value){
		return date('Y-m-d H:i:s',$value);
	}
	
	protected function getEndTimeAttr($value){
		return date('Y-m-d H:i:s',$value);
	}
	
	protected function getReleaseTimeAttr($value){
		return date('Y-m-d H:i:s',$value);
	}
	
	protected function getCreateTimeAttr($value){
		return date('Y-m-d H:i:s',$value);
	}
	
	protected function getTagsAttr($value){
		return unserialize($value);
	}
}